package com.wang.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wang.json.CustomerJackSon;
import lombok.Data;
import lombok.ToString;

import java.util.Date;

/**
 * @Classname User
 * @Description TODO
 * @Date 2024/5/17 9:40
 * @Created by pc
 */
@Data
@ToString
@JsonIgnoreProperties(value = {"word"}) // 让word 不参与序列化和反序列化
public class User {
    private String name;
    private int age;
    private boolean sex;
    private Date birthday;
    private String word;
    private double salary;

    @JsonCreator
    public User(@JsonProperty("name") String name, @JsonProperty("age") int age,
                @JsonProperty("sex") boolean sex, @JsonProperty("birthday") Date birthday,
                @JsonProperty("word") String word, @JsonProperty("salary") double salary){
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.birthday = birthday;
        this.word = word;
        this.salary = salary;
    }

    @JsonDeserialize(using = CustomerJackSon.MyDeserializer.class)
    public void setBirthday(Date birthday){
        this.birthday = birthday;
    }

    @JsonSerialize(using = CustomerJackSon.MySerializer.class)
    public double getSalary(){
        return this.salary;
    }
}
